// pages/menu/menu.js

var QQMapWX = require('../../utils/qqmap-wx-jssdk1.2/qqmap-wx-jssdk')
var qqmapsdk = new QQMapWX({
  key: 'VYSBZ-K273P-GEQD3-LLP4A-KATX2-SIBXR' // 必填
})

const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    usertype:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(app.globalData.userInfo.usertype)
    this.setData({
      usertype :app.globalData.userInfo.usertype
    })

    if(app.globalData.userInfo.faceEnable){
      if(!app.globalData.userInfo.hasFacePic){
        wx.showModal({
          title: '认证提示',
          content: '你还没录入快速登陆信息，请去录入人脸。',
          showCancel: false,//是否显示取消按钮
          //cancelText:"否",//默认是“取消”
          //cancelColor:'skyblue',//取消文字的颜色
          confirmText:"确定",//默认是“确定”
          confirmColor: 'skyblue',//确定文字的颜色
          success: function (res) {
            wx.navigateTo({
              url: '/pages/faceupload/face'
            })
          },
          fail: function (res) { },//接口调用失败的回调函数
          complete: function (res) { },//接口调用结束的回调函数（调用成功、失败都会执行）
       })
      }
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  clickSignInShop:function(){
    wx.navigateTo({
      url: '/pages/visit/shopList/shopList'
    })
  },
  clickAddShop:function(){
    wx.navigateTo({
      url: '/pages/addShop/addShop'
    })
  },
  clickAddVisiter:function(){
    wx.navigateTo({
      url: '/pages/addVisiter/addVisiter'
    })
  },
  clickPhoto:function(){
    wx.navigateTo({
      url: '/pages/logs/logs'
    })
  },
  clickMyOffLine:function(){
    wx.navigateTo({
      url: '/pages/offline/offLineList/offLineList'
    })
  },
  clickAddSchedule:function(){
    wx.navigateTo({
      url: '/pages/schedule/shopList/shopList'
    })
  },
  clickMyCode:function(){
    wx.navigateTo({
      url: '/pages/myCode/myCode'
    })
  },
  clickTaskList:function(){
    wx.navigateTo({
      url: '/pages/task/shopList/shopList'
    })
  },
  clickJingPin:function(){
    this.getMyLocation(function (pos){
      wx.scanCode({
        onlyFromCamera: true,
        scanType: ['barCode', 'qrCode', 'datamatrix', 'pdf417'],
        fail(r){
          console.log(r)
        },
        success(res){
          console.log(res)
  
         app.api.fetchGoods({code: res.result}).then(res => {
  
          console.log(res)
  
          if(res.code == 200){
            app.globalData.navParam.name = res.data.showapi_res_body.goodsName
            app.globalData.navParam.spec = res.data.showapi_res_body.spec
            app.globalData.navParam.position = pos
  
            wx.navigateTo({
              url: '/pages/jingpin/jingpin'
            })
          }else{
            wx.showToast({
              title: '无法获取商品信息',
            })
          }
         })
        }
      })
    })
  },
  getMyLocation(cb){
    let that = this;
    wx.getLocation({
      type: 'gcj02',
      success:(res) =>{
        let obj = {latitude:res.latitude,longitude:res.longitude}
        /*
        that.setData({
          jinDu:res.latitude,
          weiDu:res.longitude,
          itude:JSON.stringify(obj)
        })
        */
        qqmapsdk.reverseGeocoder({
          location: {
            latitude: res.latitude,
            longitude: res.longitude
          },
          success: (res) => {
            /*
            that.setData({
              position: res.result.address
            })
            */
            cb(res.result.address)
          }
        })
      },
      fail : res => {
        if('getLocation:fail auth deny' == res.errMsg){
          wx.showModal({
            title: '提示',
            content: '获取用户定位授权失败',
            showCancel:false,
            success(res) {
              //wx.navigateBack()
            }
          })
         }else if('getLocation:fail:ERROR_NOCELL&WIFI_LOCATIONSWITCHOFF' == res.errMsg){
          wx.showModal({
            title: '提示',
            content: '请打开手机定位',
            showCancel:false,
            success(res) {
              //wx.navigateBack()
            }
          })
        }else{
          wx.showToast({
            title: res.errMsg,
          })
        }
       },
       complete: res => {
        
       }
    })
  },

  clickMyHis:function(){
    wx.navigateTo({
      url: '/pages/scheHis/shopList/shopList'
    })
  },
  clickTempVisit:function(){
    wx.navigateTo({
      url: '/pages/tempVisit/signInTask/signInTask'
    })
  },
  clickClock:function(){
    wx.navigateTo({
      url: '/pages/clock/clock'
    })
  },
  clickClocklist:function(){
    wx.navigateTo({
      url: '/pages/clockList/clockList'
    })
  },
  clickClockHis:function(){
    wx.navigateTo({
      url: '/pages/clockHis/clockHis'
    })
  }
})